package com.jxwifi.cloud.quickclean.adapter;

import android.support.annotation.LayoutRes;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jxwifi.cloud.quickclean.R;
import com.jxwifi.cloud.quickclean.app.AccountMgr;
import com.jxwifi.cloud.quickclean.app.StateUtils;
import com.jxwifi.cloud.quickclean.bean.AssemRecordsBean;
import com.jxwifi.cloud.quickclean.bean.FeedBackBean;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.Date;

public class FeedbackAdapter extends BaseQuickAdapter<FeedBackBean, BaseViewHolder> {

    private String TAG = this.getClass().getSimpleName();
    public FeedbackAdapter(@LayoutRes int layoutResId) {
        super(layoutResId, null);
    }

    @Override
    protected void convert(BaseViewHolder helper, FeedBackBean item) {
        Log.i(TAG,"回复类型 getReplyType = "+item.getReplyType());
        if(item.getReplyType().equals("CUSTOMER")){//用户消息
            helper.getView(R.id.left_layout).setVisibility(View.GONE);
            helper.getView(R.id.right_layout).setVisibility(View.VISIBLE);
            try {
                helper.setText(R.id.right_msg, URLDecoder.decode(item.getContent(),"UTF-8"));
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            if(null != AccountMgr.getHeadImg(mContext)){
                Glide.with(mContext).load(AccountMgr.getHeadImg(mContext)).into((ImageView) helper.getView(R.id.right_pic));
            }else{
                Glide.with(mContext).load(R.mipmap.icon_default_head).into((ImageView) helper.getView(R.id.right_pic));
            }

        }else{
            helper.getView(R.id.left_layout).setVisibility(View.VISIBLE);
            helper.getView(R.id.right_layout).setVisibility(View.GONE);
            helper.setText(R.id.left_msg,item.getContent());
            //Log.i(TAG,"getFoundAvatarUrl = "+item.getFoundAvatarUrl());
            if(null != item.getFoundAvatarUrl()){
                Glide.with(mContext).load(item.getFoundAvatarUrl()).into((ImageView) helper.getView(R.id.left_pic));
            }else{
                Glide.with(mContext).load(R.mipmap.dog).into((ImageView) helper.getView(R.id.left_pic));
            }
        }
        //helper.setText(R.id.time,item.get);

        /*if (item.isCollage()){
            long seconds=0;
            try{
                SimpleDateFormat formatter=new   SimpleDateFormat   ("yyyy-MM-dd HH:mm");
                Date curDate =  new Date(System.currentTimeMillis());
                Date endDate = formatter.parse(item.getSurplusTime());
                seconds =endDate.getTime()-curDate.getTime();
//                if (seconds<=0){
//                    helper.setText(R.id.tv_ass_order_item_name,item.getProductName()+" 已过期已退款");
//                }else{
                    if (StateUtils.TD.equals(item.getCtype())){
                        helper.setText(R.id.tv_ass_order_item_name,item.getProductName()+" 已成团保洁服务有效期"+item.getDeadline());
                    }else{
                        helper.setText(R.id.tv_ass_order_item_name,item.getProductName()+" 已成团可在'我的订单'查看");
                    }
               // }
            }catch (Exception e){
                e.printStackTrace();
            }
            helper.getView(R.id.tv_ass_order_item_share).setVisibility(View.GONE);
        }else{
            //helper.getView(R.id.tv_ass_order_item_share).setVisibility(View.VISIBLE);
            helper.setText(R.id.tv_ass_order_item_name,item.getProductName()+" 未成团");
            long seconds=0;
            try{
                SimpleDateFormat formatter=new   SimpleDateFormat   ("yyyy-MM-dd HH:mm");
                Date curDate =  new Date(System.currentTimeMillis());
                Date endDate = formatter.parse(item.getSurplusTime());
                seconds =endDate.getTime()-curDate.getTime();
                //Log.i(TAG,"Cdesk = "+item.getCdesk()+" isDelete = "+item.isDelete()+" orderState = "+item.getCollageRecord()+" isCollageRecordDeleted = "+item.isCollageRecordDeleted()+" collageRecordCreateTime = "+item.getCollageRecordCreateTime());
               	
                if (seconds<=0){
                    helper.setText(R.id.tv_ass_order_item_name,item.getProductName()+"  过期未成团已退款");
                    helper.getView(R.id.tv_ass_order_item_share).setVisibility(View.GONE);
                }else{

                    if(item.isCollageRecordDeleted()){
                        helper.getView(R.id.tv_ass_order_item_share).setVisibility(View.GONE);
                    }else{
                        helper.getView(R.id.tv_ass_order_item_share).setVisibility(View.VISIBLE);
                    }
                    helper.setText(R.id.tv_ass_order_item_name,item.getProductName()+" 未成团");
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        helper.setText(R.id.tv_ass_order_item_order,"拼单编码: "+item.getCdesk());
        helper.setText(R.id.tv_ass_order_item_people_num,"拼单成团人数: "+item.getPsum());
        helper.setText(R.id.tv_ass_order_item_time,"拼单时间:"+item.getCollageRecordCreateTime());
        helper.addOnClickListener(R.id.tv_ass_order_item_share).addOnClickListener(R.id.tv_ass_order_item_check);*/
    }


}
